﻿using UnityEngine;
using System.Collections;

public class shoot_enemy2 : MonoBehaviour 
{
	public GameObject bullet_enemy;

	public GameObject player;

	public float treshold;

	public bool canShoot = true;

	// Use this for initialization
	void Start ()
	{
	
	}
	
	// Update is called once per frame
	void Update () 
	{
		Transform parentPosition = GetComponentInParent<Transform>();

		//if((parentPosition.position + transform.position).x >= player.transform.position.x - treshold || (parentPosition.position + transform.position).x <= player.transform.position.x + treshold)
		//{
		if(parentPosition.position.x + transform.position.x >= player.transform.position.x)
		{
			if(canShoot)
			{
				Instantiate(bullet_enemy, transform.position, Quaternion.identity);
			}
			canShoot = false;
		}

		//if(parentPosition.position.x + transform.position.x > player.transform.position.x + treshold)
		//{
		//	canShoot = true;
		//}


	}
}
